####Figure 1 Replication
library(foreign)
library(ggplot2)
library(np)
data<-read.dta("~/gpt_jop_replication.dta")
data<-subset(data, control_rating_1!="NA" & grant_draw!="NA")
model <- npreg(control_rating_1 ~ grant_draw, regtype="ll", data=data, bwmethod="cv.aic", gradients=T) 
plot(model, plot.errors.method="bootstrap", plot.errors.type="quantile", xlab="Millions of Dollars Announced", ylab="Feeling Thermometer",ylim=c(0,100),xlim=c(0,10))
points(data$grant_draw, data$control_rating_1, pch=19, cex=.1)

###Figure A1
par(mfrow=c(2,2))
data<-read.dta("~/gpt_jop_replication.dta")
data<-subset(data, context_one!="NA" & treatment_rating1_1!="NA")
data$c1_fig<-NA
data$c1_fig[data$context_one=="50% less than"]<-1
data$c1_fig[data$context_one=="25% less than"]<-2
data$c1_fig[data$context_one=="5% less than"]<-3
data$c1_fig[data$context_one=="the same amount as"]<-4
data$c1_fig[data$context_one=="5% more than"]<-5
data$c1_fig[data$context_one=="25% more than"]<-6
data$c1_fig[data$context_one=="50% more than"]<-7
data$c1_fig[data$context_one=="100% more than"]<-8
data$c1_fig[data$context_one=="200% more than"]<-9


png("~/gpt_figure_a1.png", width=1200, height=1200)
par(mfrow=c(2,2))

plot(data$c1_fig, data$treatment_rating1_1, data=data, xlim=c(1,9), ylim=c(0,100), pch=19, cex=.1, xlab="Grant Context", ylab="Feeling Thermometer", axes=F, main="First Round", cex.lab=1.6, cex.main=1.6)

axis(1, at=c(1:9), labels=c("-50%", "-25%", "-5%", "=", "+5%", "+25%", "+50%", "+100%", "+200%"), cex.axis=1.5)
axis(2, at=c(10, 20, 30, 40, 50, 60, 70, 80, 90), labels=c("10", "20", "30", "40", "50", "60", "70", "80", "90"), cex.axis=1.5)

points(1, 63.15, cex=1.5, pch=19, col="red")
points(2, 64.59, cex=1.5, pch=19, col="red")
points(3, 65.86, cex=1.5, pch=19, col="red")
points(4, 71.49, cex=1.5, pch=19, col="black")
points(5, 68.60, cex=1.5, pch=19, col="blue")
points(6, 71.92, cex=1.5, pch=19, col="blue")
points(7, 67.60, cex=1.5, pch=19, col="blue")
points(8, 63.73, cex=1.5, pch=19, col="blue")
points(9, 70.54, cex=1.5, pch=19, col="blue")

segments(1,58.97, 1,67.32, col="red", lwd = 3)
segments(2,59.99, 2,69.19, col="red", lwd = 3)
segments(3,60.89, 3,70.83, col="red", lwd = 3)
segments(4,67.80, 4, 75.18, col="black", lwd = 3)
segments(5,63.85, 5,73.34, col="blue", lwd = 3)
segments(6,67.96, 6,75.87, col="blue", lwd = 3)
segments(7,61.80, 7,74.40, col="blue", lwd = 3)
segments(8,58.45, 8,69.02, col="blue", lwd = 3)
segments(9,66.45, 9,74.64, col="blue", lwd = 3)
box()


legend("bottomleft", c("p=0.018"), text.col=c("red", "blue"), cex=2, title="Hyp. Test that <0 not equal to >0", pt.cex = 3.4)

###Round 2
data<-read.dta("~/gpt_jop_replication.dta")
data<-subset(data, context_two!="NA" & treatment_rating2_1!="NA")
data$c2_fig<-NA
data$c2_fig[data$context_two=="50% less than"]<-1
data$c2_fig[data$context_two=="25% less than"]<-2
data$c2_fig[data$context_two=="5% less than"]<-3
data$c2_fig[data$context_two=="the same amount as"]<-4
data$c2_fig[data$context_two=="5% more than"]<-5
data$c2_fig[data$context_two=="25% more than"]<-6
data$c2_fig[data$context_two=="50% more than"]<-7
data$c2_fig[data$context_two=="100% more than"]<-8
data$c2_fig[data$context_two=="200% more than"]<-9

plot(data$c2_fig, data$treatment_rating1_1, data=data, xlim=c(1,9), ylim=c(0,100), pch=19, cex=.1, xlab="Grant Context", ylab="Feeling Thermometer", axes=F, main="Second Round", cex.lab=1.6, cex.main=1.6)

axis(1, at=c(1:9), labels=c("-50%", "-25%", "-5%", "=", "+5%", "+25%", "+50%", "+100%", "+200%"), cex.axis=1.5)
axis(2, at=c(10, 20, 30, 40, 50, 60, 70, 80, 90), labels=c("10", "20", "30", "40", "50", "60", "70", "80", "90"), cex.axis=1.5)

points(1, 49.36, cex=1.5, pch=19, col="red")
points(2, 51.73, cex=1.5, pch=19, col="red")
points(3, 59.66, cex=1.5, pch=19, col="red")
points(4, 67.22, cex=1.5, pch=19, col="black")
points(5, 64.23, cex=1.5, pch=19, col="blue")
points(6, 71.81, cex=1.5, pch=19, col="blue")
points(7, 67.16, cex=1.5, pch=19, col="blue")
points(8, 66.75, cex=1.5, pch=19, col="blue")
points(9, 67.15, cex=1.5, pch=19, col="blue")

segments(1,44.63, 1,54.09, col="red", lwd = 3)
segments(2,47.09, 2,56.36, col="red", lwd = 3)
segments(3,53.87, 3,65.45, col="red", lwd = 3)
segments(4,62.62, 4, 71.83, col="black", lwd = 3)
segments(5,59.98, 5,68.49, col="blue", lwd = 3)
segments(6,68.02, 6,75.61, col="blue", lwd = 3)
segments(7,62.34, 7,71.98, col="blue", lwd = 3)
segments(8,61.43, 8,72.07, col="blue", lwd = 3)
segments(9,61.00, 9,73.30, col="blue", lwd = 3)

box()
legend("bottomleft", c("p=0.000"), text.col=c("red", "blue"), cex=2, title="Hyp. Test that <0 not equal to >0", pt.cex = 3.4)

###Round 3
data<-read.dta("~/gpt_jop_replication.dta")
data$c3_fig<-NA
data$c3_fig[data$context_three=="50% less than"]<-1
data$c3_fig[data$context_three=="25% less than"]<-2
data$c3_fig[data$context_three=="5% less than"]<-3
data$c3_fig[data$context_three=="the same amount as"]<-4
data$c3_fig[data$context_three=="5% more than"]<-5
data$c3_fig[data$context_three=="25% more than"]<-6
data$c3_fig[data$context_three=="50% more than"]<-7
data$c3_fig[data$context_three=="100% more than"]<-8
data$c3_fig[data$context_three=="200% more than"]<-9

plot(data$c3_fig, data$treatment_rating1_1, data=data, xlim=c(1,9), ylim=c(0,100), pch=19, cex=.1, xlab="Grant Context", ylab="Feeling Thermometer", axes=F, main="Third Round", cex.lab=1.6, cex.main=1.6)
axis(1, at=c(1:9), labels=c("-50%", "-25%", "-5%", "=", "+5%", "+25%", "+50%", "+100%", "+200%"), cex.axis=1.5)
axis(2, at=c(10, 20, 30, 40, 50, 60, 70, 80, 90), labels=c("10", "20", "30", "40", "50", "60", "70", "80", "90"), cex.axis=1.5)


points(1, 46.92, cex=1.5, pch=19, col="red")
points(2, 51.73, cex=1.5, pch=19, col="red")
points(3, 56.21, cex=1.5, pch=19, col="red")
points(4, 63.44, cex=1.5, pch=19, col="black")
points(5, 70.17, cex=1.5, pch=19, col="blue")
points(6, 65.48, cex=1.5, pch=19, col="blue")
points(7, 70.28, cex=1.5, pch=19, col="blue")
points(8, 70.73, cex=1.5, pch=19, col="blue")
points(9, 71.77, cex=1.5, pch=19, col="blue")

segments(1,40.26, 1,53.58, col="red", lwd = 3)
segments(2,47.05, 2,56.42, col="red", lwd = 3)
segments(3,52.19, 3,60.24, col="red", lwd = 3)
segments(4,58.26, 4, 68.62, col="black", lwd = 3)
segments(5,65.59, 5,74.76, col="blue", lwd = 3)
segments(6,60.33, 6,70.63, col="blue", lwd = 3)
segments(7,65.96, 7,74.60, col="blue", lwd = 3)
segments(8,65.48, 8,75.98, col="blue", lwd = 3)
segments(9,66.24, 9,77.29, col="blue", lwd = 3)
box()
legend("bottomleft", c("p=0.000"), text.col=c("red", "blue"), cex=2, title="Hyp. Test that <0 not equal to >0", pt.cex = 3.4)


###Pooled. Note, we use a pooled data set for this.
data<-read.dta("~/gpt_replication_pooled.dta")
data$cp_fig<-NA
data$cp_fig[data$experiment_context==.5]<-1
data$cp_fig[data$experiment_context==.75]<-2
data$cp_fig[data$experiment_context>.9 & data$experiment_context<1]<-3
data$cp_fig[data$experiment_context==1]<-4
data$cp_fig[data$experiment_context>1 & data$experiment_context<1.1]<-5
data$cp_fig[data$experiment_context==1.25]<-6
data$cp_fig[data$experiment_context==1.5]<-7
data$cp_fig[data$experiment_context==2]<-8
data$cp_fig[data$experiment_context==3]<-9
plot(data$cp_fig, data$treatment_rating1_1, data=data, xlim=c(1,9), ylim=c(0,100), pch=19, cex=.1, xlab="Grant Context", ylab="Feeling Thermometer", axes=F, main="Pooled", cex.lab=1.6, cex.main=1.6)
axis(1, at=c(1:9), labels=c("-50%", "-25%", "-5%", "=", "+5%", "+25%", "+50%", "+100%", "+200%"), cex.axis=1.5)
axis(2, at=c(10, 20, 30, 40, 50, 60, 70, 80, 90), labels=c("10", "20", "30", "40", "50", "60", "70", "80", "90"), cex.axis=1.5)


points(1, 54.56, cex=1.5, pch=19, col="red")
points(2, 55.49, cex=1.5, pch=19, col="red")
points(3, 60.36, cex=1.5, pch=19, col="red")
points(4, 67.71, cex=1.5, pch=19, col="black")
points(5, 67.52, cex=1.5, pch=19, col="blue")
points(6, 69.70, cex=1.5, pch=19, col="blue")
points(7, 68.51, cex=1.5, pch=19, col="blue")
points(8, 66.96, cex=1.5, pch=19, col="blue")
points(9, 69.91, cex=1.5, pch=19, col="blue")
box()

segments(1,51.60, 1,57.52, col="red", lwd = 3)
segments(2,52.73, 2,58.24, col="red", lwd = 3)
segments(3,57.56, 3,63.16, col="red", lwd = 3)
segments(4,65.15, 4, 70.27, col="black", lwd = 3)
segments(5,64.93, 5,70.12, col="blue", lwd = 3)
segments(6,67.19, 6,72.21, col="blue", lwd = 3)
segments(7,65.72, 7,71.29, col="blue", lwd = 3)
segments(8,63.92, 8,69.99, col="blue", lwd = 3)
segments(9,66.92, 9,72.9, col="blue", lwd = 3)
legend("bottomleft", c("p=0.000"), text.col=c("red", "blue"), cex=2, title="Hyp. Test that <0 not equal to >0", pt.cex = 3.4)

dev.off()

###Figure A2
data<-read.dta("~/gpt_jop_replication.dta")
data$eval_dif_1_2=data$treatment_rating2_1-data$treatment_rating1_1
data$eval_dif_2_3=data$treatment_rating3_1-data$treatment_rating2_1
data$early_mean=(data$treatment_rating2_1+data$treatment_rating1_1)/2
data$eval_mean_diff=data$treatment_rating3_1-data$early_mean

data$c1_fig<-NA
data$c1_fig[data$context_one=="50% less than"]<-1
data$c1_fig[data$context_one=="25% less than"]<-2
data$c1_fig[data$context_one=="5% less than"]<-3
data$c1_fig[data$context_one=="the same amount as"]<-4
data$c1_fig[data$context_one=="5% more than"]<-5
data$c1_fig[data$context_one=="25% more than"]<-6
data$c1_fig[data$context_one=="50% more than"]<-7
data$c1_fig[data$context_one=="100% more than"]<-8
data$c1_fig[data$context_one=="200% more than"]<-9

data$c2_fig<-NA
data$c2_fig[data$context_two=="50% less than"]<-1
data$c2_fig[data$context_two=="25% less than"]<-2
data$c2_fig[data$context_two=="5% less than"]<-3
data$c2_fig[data$context_two=="the same amount as"]<-4
data$c2_fig[data$context_two=="5% more than"]<-5
data$c2_fig[data$context_two=="25% more than"]<-6
data$c2_fig[data$context_two=="50% more than"]<-7
data$c2_fig[data$context_two=="100% more than"]<-8
data$c2_fig[data$context_two=="200% more than"]<-9

data$c3_fig<-NA
data$c3_fig[data$context_three=="50% less than"]<-1
data$c3_fig[data$context_three=="25% less than"]<-2
data$c3_fig[data$context_three=="5% less than"]<-3
data$c3_fig[data$context_three=="the same amount as"]<-4
data$c3_fig[data$context_three=="5% more than"]<-5
data$c3_fig[data$context_three=="25% more than"]<-6
data$c3_fig[data$context_three=="50% more than"]<-7
data$c3_fig[data$context_three=="100% more than"]<-8
data$c3_fig[data$context_three=="200% more than"]<-9

data$cont_diff_1_2=data$c2_fig-data$c1_fig
data$cont_diff_2_3=data$c3_fig-data$c2_fig
data$cont_mean=(data$c2_fig+data$c1_fig)/2
data$cont_mean_diff=data$c3_fig-data$cont_mean

par(mfrow=c(1,3))
model <- npreg(eval_dif_1_2 ~ cont_diff_1_2, regtype="ll", data=data, bwmethod="cv.aic", gradients=T) 
plot(model, plot.errors.method="bootstrap", plot.errors.type="quantile", xlab="Change in Context Units", ylab="Change in Feeling Thermometer", main="Change from Wave 1 to 2", ylim=c(-100,100),xlim=c(-8,8), cex.main=2, cex.axis=2)
points(data$cont_diff_1_2, data$eval_dif_1_2, pch=19, cex=.1)

model <- npreg(eval_dif_2_3 ~ cont_diff_2_3, regtype="ll", data=data, bwmethod="cv.aic", gradients=T) 
plot(model, plot.errors.method="bootstrap", plot.errors.type="quantile", xlab="Change in Context Units", ylab="Change in Feeling Thermometer", main="Change from Wave 2 to 3", ylim=c(-100,100),xlim=c(-8,8),cex.main=2, cex.axis=2)
points(data$cont_diff_2_3, data$eval_dif_2_3, pch=19, cex=.1)

model <- npreg(eval_mean_diff ~ cont_mean_diff, regtype="ll", data=data, bwmethod="cv.aic", gradients=T) 
plot(model, plot.errors.method="bootstrap", plot.errors.type="quantile", xlab="Change in Context Units", ylab="Change in Feeling Thermometer", main="Change from Mean of Wave 2 to Wave 3", ylim=c(-100,100),xlim=c(-8,8),cex.main=2, cex.axis=2)
points(data$cont_mean_diff, data$eval_mean_diff, pch=19, cex=.1)


###Figure for party match

####Figure A3 Replication
library(foreign)
library(ggplot2)
library(np)
#data<-read.dta("C:\\Users\\ptucker\\Dropbox\\Patashnik_Gerber_Project\\data_for_alan_eric.dta")
data<-read.dta("~/gpt_jop_replication.dta")

rep_rep=subset(data, pid1=="Republican" & pid=="R")
rep_dem=subset(data, pid1=="Republican" & pid=="D")

dem_rep=subset(data, pid1=="Democrat" & pid=="R")
dem_dem=subset(data, pid1=="Democrat" & pid=="D")

match=subset(data, (pid1=="Democrat" & pid=="D") | (pid1=="Republican" & pid=="R"))
nomatch=subset(data, (pid1=="Democrat" & pid=="R") | (pid1=="Republican" & pid=="D"))



loessMod50 <- loess(rep_rep$control_rating_1 ~ rep_rep$grant_draw, span=0.75)
plot(rep_rep$grant_draw, rep_rep$control_rating_1, pch=19, xlab="Millions of Dollars Announced", ylab="Feeling Thermometer", cex=.1, col="red", main="Republican Subjects")

smoothed50 <- predict(loessMod50) 
rep_rep<-subset(rep_rep, control_rating_1!="NA")
lines(smoothed50, x=rep_rep$grant_draw, col="red")
loessMod50 <- loess(rep_dem$control_rating_1 ~ rep_dem$grant_draw, span=0.75)
smoothed50 <- predict(loessMod50)
rep_dem<-subset(rep_dem, control_rating_1!="NA")
lines(smoothed50, x=rep_dem$grant_draw, col="blue")
points(rep_dem$grant_draw, rep_dem$control_rating_1, pch=19, cex=.1, col="blue")
legend("bottomleft", c("Republican Evaluating Republican", "Republican Evaluating Democrat"), lty=1, col=c("red", "blue"))



loessMod50 <- loess(dem_dem$control_rating_1 ~ dem_dem$grant_draw, span=0.75)
plot(dem_dem$grant_draw, dem_dem$control_rating_1, pch=19, xlab="Millions of Dollars Announced", ylab="Feeling Thermometer", cex=.1, col="red", main="Democratic Subjects")

smoothed50 <- predict(loessMod50) 
dem_dem<-subset(dem_dem, control_rating_1!="NA")
lines(smoothed50, x=dem_dem$grant_draw, col="blue")
loessMod50 <- loess(dem_rep$control_rating_1 ~ dem_rep$grant_draw, span=0.75)
smoothed50 <- predict(loessMod50)
dem_rep<-subset(dem_rep, control_rating_1!="NA")
lines(smoothed50, x=dem_rep$grant_draw, col="red")
points(dem_rep$grant_draw, dem_rep$control_rating_1, pch=19, cex=.1, col="blue")
legend("bottomleft", c("Democratic Evaluating Republican", "Democratic Evaluating Democrat"), lty=1, col=c("red", "blue"))



loessMod50 <- loess(match$control_rating_1 ~ match$grant_draw, span=0.75)
plot(match$grant_draw, match$control_rating_1, pch=19, xlab="Millions of Dollars Announced", ylab="Feeling Thermometer", cex=.1, col="blue", main="Democratic and Republican Subjects")

smoothed50 <- predict(loessMod50) 
match<-subset(match, control_rating_1!="NA")
lines(smoothed50, x=match$grant_draw, col="blue")
loessMod50 <- loess(nomatch$control_rating_1 ~ nomatch$grant_draw, span=0.75)
smoothed50 <- predict(loessMod50)
nomatch<-subset(nomatch, control_rating_1!="NA")
lines(smoothed50, x=nomatch$grant_draw, col="red")
points(nomatch$grant_draw, nomatch$control_rating_1, pch=19, cex=.1, col="red")
legend("bottomleft", c("Respondents of Same Party as Legislator", "Respondents of Opposite Party as Legislator"), lty=1, col=c("red", "blue"))
